<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="企业用户" prop="userinformation.id"
                :rules="[
                  {required: true, message:'企业用户不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择企业用户"
            labelName = 'userName'
            labelValue = 'id'
            :value = "inputForm.userinformation.id"
            :limit="1"
            @getValue='(value) => {inputForm.userinformation.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            dataListUrl="/dlyrl/hr/enterpriseuserinformation/enterpriseUserInformation/list"
            entityBeanName="enterpriseUserInformation"
            queryEntityUrl="/dlyrl/hr/enterpriseuserinformation/enterpriseUserInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="企业" prop="enterprise.id"
                :rules="[
                  {required: true, message:'企业不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择企业"
            labelName = 'companyName'
            labelValue = 'id'
            :value = "inputForm.enterprise.id"
            :limit="1"
            @getValue='(value) => {inputForm.enterprise.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'companyName',
              label: '企业名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'companyName',
              label: '企业名称'
            }
            ]"
            dataListUrl="/dlyrl/hr/enterpriseinformation/enterpriseInformation/list"
            entityBeanName="enterpriseInformation"
            queryEntityUrl="/dlyrl/hr/enterpriseinformation/enterpriseInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="金额" prop="moneyCount"
                :rules="[
                  {required: true, message:'金额不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.moneyCount" placeholder="请填写金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="操作时间" prop="doDate"
                :rules="[
                  {required: true, message:'操作时间不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.doDate"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="操作类型" prop="doType"
                :rules="[
                  {required: true, message:'操作类型不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.doType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('doType_E')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="交易账户" prop="transactionAccount"
                :rules="[
                  {required: true, message:'交易账户不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.transactionAccount" placeholder="请填写交易账户"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="操作内容" prop="doContent"
                :rules="[
                  {required: true, message:'操作内容不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.doContent" placeholder="请填写操作内容"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="交易账户标题" prop="transactionAccountTitle"
                :rules="[
                  {required: true, message:'交易账户标题不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.transactionAccountTitle" placeholder="请填写交易账户标题"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="交易类型" prop="transactionType"
                :rules="[
                  {required: true, message:'交易类型不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.transactionType" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('dealType_E')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        
        <el-col :span="12">
            <el-form-item label="任务id/商品id" prop="taskOrGoods"
                :rules="[
                  {required: true, message:'任务id/商品id不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.taskOrGoods" placeholder="请填写任务id/商品id"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
        
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          userinformation: {
            id: ''
          },
          enterprise: {
            id: ''
          },
          moneyCount: '',
          doDate: '',
          doType: '',
          transactionAccount: '',
          doContent: '',
          transactionAccountTitle: '',
          transactionType: '',
          remarks: '',
          taskOrGoods: ''
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建企业账单明细`
        } else if (method === 'edit') {
          this.title = '修改企业账单明细'
        } else if (method === 'view') {
          this.title = '查看企业账单明细'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/lhyg/lgy/enterprisebilldetail/enterpriseBillDetail/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.enterpriseBillDetail)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/lhyg/lgy/enterprisebilldetail/enterpriseBillDetail/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>